<template>
  <el-main>
    <el-form :model="ReginForm"
             ref="ReginForm"
             :rules="rule"
             class="regform"
             label-width="0">
      <h3 class="login-text">手机注册</h3>
      <el-form-item prop="tel">
        <el-input type="text"
                  v-model.number="ReginForm.tel"
                  placeholder="手机号码">
        </el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input type="password"
                  v-model="ReginForm.password"
                  placeholder="密码">
        </el-input>
      </el-form-item>
      <div>
        <input class="auth_input"
               type="text"
               v-model="verification"
               placeholder="输入验证码" />
        <span v-show="sendAuthCode"
              class="auth_text auth_text_blue"
              @click="getAuthCode">获取验证码</span>
        <span v-show="!sendAuthCode"
              class="auth_text"> <span class="auth_text_blue">{{auth_time}} </span> 秒之后重新发送验证码</span>
      </div>
      <el-form-item>
        <el-button type="success"
                   class="submitBtn"
                   round
                   @click.native.prevent="submit"
                   :loading="logining">
          注册
        </el-button>
        <hr>
        <p>已经有账号，马上去<span class="to"
                @click="tologin">登录</span></p>
      </el-form-item>
    </el-form>
  </el-main>
</template>

<script>
export default {
  name: 'Login',
  components: {},
  data () {
    let confirmpasswordCheck = (rule, value, callback) => {
      if (value === '') {
        return callback(new Error('密码是必须的'))
      } else {
        return callback()
      }
    }
    let telCheck = (rule, value, callback) => {
      if (value === '') {
        return callback(new Error('电话号码是必须的'))
      } else if (!Number.isInteger(value)) {
        return callback(new Error('电话号码必须是数字'))
      } else if (value.toString().length !== 11) {
        return callback(new Error('电话号码必须是11位数字'))
      } else {
        callback()
      }
    }
    return {
      ReginForm: {
        password: '',
        tel: '',
      },
      logining: false,
      sendAuthCode: true,/*布尔值，通过v-show控制显示‘获取按钮'还是‘倒计时' */
      auth_time: 0, /*倒计时 计数器*/
      verification: "",//绑定输入验证码框框
      rule: {
        password: [
          {
            required: true,
            message: '密码是必须的！',
            trigger: 'blur'
          }
        ],
        tel: [
          {
            required: true,
            validator: telCheck,
            trigger: 'blur'
          }
        ],
      }
    }
  }
}
}
</script>

<style scoped lang="stylus"></style>
